#include<iostream>
using namespace std;
int r[200001];
int a[200001];
int main() {
	freopen("fruit.in","r",stdin); 
	freopen("fruit.out","w",stdout);
	int n,sum;cin>>n;sum=n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		r[i]=i+1;
	}
	r[0]=1;r[n]=-1;
	for(int i=0;sum>0;i++) {
		a[0]=!a[r[0]];
		int ll=0;
		while(ll!=-1) {
			if(a[ll]!=a[r[ll]]){
				cout<<r[ll]<<' ';sum--;
				r[ll]=r[r[ll]];
			}
			ll=r[ll];
		}
		cout << endl;
	}
	return 0;
}
